#include <iostream>
#include <vector>
#include <algorithm>

struct Point
{
    int x;
    double y;

    // 自定义比较函数， std::find
    bool operator==(const Point &rhs) const
    {
        return x == rhs.x;
    }
};

int main(int argc, char const *argv[])
{
    Point p;
    p.x = 0;
    p.y = 0;
    int i = 0;
    std::vector<Point> pointVec(10, p);
    for (auto &v : pointVec)
    {   
        v.x = i++;
        v.y = v.x;
    }

    // for (auto iter = pointVec.begin(); iter != pointVec.end(); iter++)
    // {
    //     std::cout << (*iter).x << " " << (*iter).y << "\n";
    //     if (iter->x == 3)
    //         iter->y = iter->y + 100;
    // }
    std::for_each(pointVec.begin(), pointVec.end(), [](Point &p) {
        std::cout << p.x << " " << p.y << "\n";
        if (p.x == 3) p.y = p.y + 100; 
    });

    auto &v = pointVec.back();
    v.y = 100;
    for (auto it = pointVec.begin(); it != pointVec.end(); it++)
    {
        if (it->x % 2 == 0)
            pointVec.erase(it);
    }

    // 重写==
    p.x = 3;
    auto it = std::find(pointVec.begin(), pointVec.end(), p);
    std::cout << it->x << " " << it->y << "\n";

    // lambda 表达式
    std::for_each(pointVec.begin(), pointVec.end(), [](Point p)
                  { std::cout << p.x << " " << p.y << "\n"; });

    // lambda 表达式
    it = std::find_if(pointVec.begin(), pointVec.end(), [](Point p)
                      { return p.x == 5; });
    std::cout << it->x << " " << it->y << "\n";

    return 0;
}
